﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pro260Website.Controllers
{
    public class SearchController : Controller
    {
        public ActionResult AmazonSearch(string searchItem)
        {
            string amazonQuery = "http://www.amazon.com/s?url=search-alias%3Daps&field-keywords=" + FormatSearch(searchItem);
            
            return Redirect(amazonQuery);
        }

        public ActionResult GamestopSearch(string searchItem)
        {
            string gamestopQuery = "http://www.gamestop.com/browse?nav=16k-" + FormatSearch(searchItem);

            return Redirect(gamestopQuery);
        }

        public ActionResult GoogleShoppingSearch(string searchItem)
        {
            string googleShoppingQuery = "https://www.google.com/search?tbm=shop&q=" + FormatSearch(searchItem);

            return Redirect(googleShoppingQuery);
        }

        public string FormatSearch(string input)
        {
            string[] values = input.Split(' ');
            string formatted = values[0];
            for (int i = 1; i < values.Length; i++)
            {
                formatted = formatted + "+" + values[i];
            }
            return formatted;
        }
    }
}
